package com.woniuxy.qiantai.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class UserOrderMQConfig {

    //声明以下内容:  交换机   队列   以及交换和队列的绑定关系
    //用户死信交换机
    @Bean
    public DirectExchange userDeadExchange(){
        return new DirectExchange("userDeadExchange");
    }
    //用户死信队列
    @Bean
    public Queue userDeadQueue(){
        return new Queue("userDeadQueue");
    }

    //用户死信交换机和队列绑定
    @Bean
    public Binding userDeadBinding(){
        return BindingBuilder.bind(userDeadQueue())
                .to(userDeadExchange())
                .with("userDeadRouting");
    }

    //用户普通交换机
    @Bean
    public DirectExchange userNormalExchange(){
        return new DirectExchange("userNormalExchange");
    }
    //用户普通交换机和普通队列绑定
    @Bean
    public Binding userNormalBinding(){
        return BindingBuilder.bind(userNormalQueue())
                .to(userNormalExchange())
                .with("userNormalRouting");
    }
    //普通队列不能被其它消费者监听消费
    //用户普通队列和死信交换机绑定
    @Bean
    public Queue userNormalQueue(){
        return QueueBuilder.durable("userNormalQueue")
                .deadLetterExchange("userDeadExchange")
                .deadLetterRoutingKey("userDeadRouting")
                .ttl(2*60*1000)
                .build();
    }
}
